package com.star.entry;

import com.star.Main;
import com.star.entry.utils.noob;
import com.star.test.entity.Students;
import org.w3c.dom.Node;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.invoke.VarHandle;
import java.math.BigDecimal;
import java.util.*;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class entryMain {

    public static void main(String[] args) throws IOException {
        //noob39();
        //noob40();
        //noob41();
        //noob42();
        //noob43();
        //noob44();
        //noob45();
        //noob46();
        //noob54();
        //noob55();
        //noob56();
        //noob57();
        //noob58();
        //noob59();
        //noob60();

        //node69();
        //node70();
        //node76();
        node83();


    }


    private static void noob39() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("enter the number");
        int n = scanner.nextInt();
        System.out.println(noob.Sequence(n));
    }

    /*二维斐波那契数列*/
    private static void noob40() {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        System.out.println(noob.fibonacciSequence(m, n));
    }

    /*在远古遗迹中，探险家们在石碑上发现了一系列关键信息，这些信息被刻录成一串整数序列，以数字
    0作为结束标志。为了触发机关，需要将这串刻碑数字倒序读取（不包括结束标志 0）。
    现在，请你编写程序，帮助探险家完成这一倒序读取的任务。*/
    private static void noob41() {
        Scanner in = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<>();
        while (in.hasNextInt()) {
            int number = in.nextInt();
            if (number == 0) {
                break;
            }
            list.add(number);
        }
        Collections.reverse(list);
        System.out.println(list
                .stream()
                .map(String::valueOf)
                .collect(Collectors.joining(" ")));
    }

    /*左侧严格小于计数,对于每个位置 i ，统计在它前面（索引 j<i ）有多少个元素比ai小。*/
    private static void noob42() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); // 读入数量
        ArrayList<Integer> list = new ArrayList<>();
        int[] a = new int[n];

        // 读入 n 个数
        for (int i = 0; i < n; i++) {
            list.add(scanner.nextInt());
        }

        // 计算 b[i]
        ArrayList<Integer> result = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int count = 0;
            for (int j = 0; j < i; j++) { // j < i，不包含 i
                if (list.get(j) < list.get(i)) {
                    count++;
                }
            }
            result.add(count);
        }

        // 输出结果，空格分隔，去掉 [] 和 ,
        System.out.println(result.stream().map(String::valueOf).collect(Collectors.joining(" ")));
    }

    /*快速计算每张试卷的极差和方差。*/
    private static void noob43() {
        Scanner sc = new Scanner(System.in);

        int number = sc.nextInt();  // 试卷数量

        for (int i = 0; i < number; i++) {
            int n = sc.nextInt();  // 每张试卷的整数个数
            long[] a = new long[n];
            long sum = 0;
            // 读入数据，同时计算最大值、最小值和总和
            for (int j = 0; j < n; j++) {
                a[j] = sc.nextLong();
                sum += a[j];
            }
            // 计算平均值（double！）
            double average = (double) sum / n;

            // 计算极差
            Arrays.sort(a);
            long min = a[0];
            long max = a[n - 1];
            long range = max - min;

            // 计算方差
            double variance = 0.0;
            for (long x : a) {
                double diff = x - average;
                variance += diff * diff;
            }
            variance = variance / n;

            // 输出：极差（整数） + 方差（保留3位小数）
            System.out.println(range + " " + String.format("%.3f", variance));
        }
    }

    /*数组计数维护*/
    private static void noob44() {
        Scanner scanner = new Scanner(System.in);
        //测试用例组数
        int groups = scanner.nextInt();
        //初始化
        int S = 0, cnt = 0;
        //读取每一组测试用例
        for (int i = 0; i < groups; i++) {
            S = 0;
            cnt = 0;
            //正整数个数
            int n = scanner.nextInt();
            //阈值
            int k = scanner.nextInt();
            int[] a = new int[n];
            for (int j = 0; j < n; j++) {
                a[j] = scanner.nextInt();
                if (a[j] >= k) {
                    S = S + a[j];
                }
                if (a[j] == 0 && S >= 1) {
                    S--;
                    cnt++;
                }
            }
            System.out.println(cnt);

        }
    }

    /*计算在区间 1 到 n的所有整数中，数字 x 共出现了多少次。*/
    private static void noob45() {
        Scanner scanner = new Scanner(System.in);
        //获取上界
        int limit = scanner.nextInt();
        //获取要统计的数字
        int number = scanner.nextInt();
        char s_number = String.valueOf(number).charAt(0);
        int count = 0;
        for (int i = 1; i <= limit; i++) {
            for (char c : String.valueOf(i).toCharArray()) {
                if (c == s_number) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }

    /*有 n个人(0∼n−1）围成一圈，从编号为 k 的人开始报数，报数依次为1,2,…,m，
    报到 m的人出队。下次从出队者的下一个人开始重新报数，循环往复，直到队伍中只剩最后一个人，该人即"大王"。
    给定三个正整数 n,k,m，请输出最后剩下的"大王"编号。*/
    private static void noob46() {
        Scanner scanner = new Scanner(System.in);
        //获取总人数
        int n = scanner.nextInt();
        //获取编号
        int k = scanner.nextInt();
        //获取报数
        int m = scanner.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(i);
        }
        int start = k;

        while (list.size() > 1) {
            // 计算第m个人的位置（从start开始数）
            int index = (start + m - 1) % list.size();
            list.remove(index);

            // 下一轮从被移除的人的下一个开始报数
            // 如果index是最后一个，则下一轮从0开始；否则从index开始
            if (index == list.size()) {
                start = 0;
            } else {
                start = index;
            }
        }

        System.out.println(list.get(0).toString());
    }

    /*斗兽棋*/
    private static void noob54() {
        Scanner in = new Scanner(System.in);
        String s1 = in.next();
        String s2 = in.next();

        if ((s1.equals("elephant") && s2.equals("tiger")) ||
                (s1.equals("tiger") && s2.equals("cat")) ||
                (s1.equals("cat") && s2.equals("mouse")) ||
                (s1.equals("mouse") && s2.equals("elephant"))) {
            System.out.println("win");
        } else if ((s2.equals("elephant") && s1.equals("tiger")) ||
                (s2.equals("tiger") && s1.equals("cat")) ||
                (s2.equals("cat") && s1.equals("mouse")) ||
                (s2.equals("mouse") && s1.equals("elephant"))) {
            System.out.println("lose");
        } else {
            System.out.println("tie");
        }

    }

    /*添加逗号*/
    private static void noob55() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String input = reader.readLine();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < input.length(); i++) {
            sb.append(input.charAt(i));
        }
        for (int i = input.length(); i > 0; i = i - 3) {
            if (i != input.length()) {
                sb.insert(i, ",");
            }
        }
        System.out.println(sb);
    }

    /*BFS*/
    private static void noob56() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String input = reader.readLine();
        String word = "Bob";
        input = input.toLowerCase();
        if (input.contains(word.toLowerCase())) {
            System.out.println(input.indexOf(word.toLowerCase()));
        } else
            System.out.println(-1);
    }

    /*凯撒加密*/
    private static void noob57() throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int digits = Integer.parseInt(reader.readLine()) % 26;
        char[] password = reader.readLine().toCharArray();
        for (int i = 0; i < password.length; i++) {
            password[i] = (char) (password[i] + digits);
            if (password[i] > 'z') {
                password[i] = (char) (password[i] - 26);
            }
        }
        System.out.println(password);
    }

    /*无限长正整数排列字符串*/
    private static void noob58() throws IOException {
        int n = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
        int pos = 0; // 已遍历字符总数
        for (int num = 1; ; num++) { // 从1开始，符合题意
            String s = String.valueOf(num);
            for (int j = 0; j < s.length(); j++) {
                pos++;
                if (pos == n) {
                    System.out.println(s.charAt(j));
                    return; // 找到就退出，不浪费
                }
            }
        }
    }

    /*简写单词*/
    private static void noob59() throws IOException {
        String input = new BufferedReader(new InputStreamReader(System.in)).readLine();
        String[] split = input.split(" ");
        for (int i = 0; i < split.length; i++) {
            System.out.print(split[i].toUpperCase().charAt(0));
        }
    }


    /*牛牛的考试*/
    private static void noob60() throws IOException {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        scanner.nextLine(); //消耗掉 nextInt() 后的换行符

        for (int i = 0; i < T; i++) {
            String A = scanner.nextLine();
            String B = scanner.nextLine();
            String C = scanner.nextLine();
            String D = scanner.nextLine();

            int lenA = A.length();
            int lenB = B.length();
            int lenC = C.length();
            int lenD = D.length();

            int[] lens = {lenA, lenB, lenC, lenD};
            char[] opts = {'A', 'B', 'C', 'D'};

            int min = Arrays.stream(lens).min().getAsInt();
            int max = Arrays.stream(lens).max().getAsInt();

            long countMin = Arrays.stream(lens).filter(x -> x == min).count();
            long countMax = Arrays.stream(lens).filter(x -> x == max).count();

            boolean uniqueMin = (countMin == 1); // 是否恰有一个最短
            boolean uniqueMax = (countMax == 1); // 是否恰有一个最长
            System.out.println();
            if (uniqueMin && !uniqueMax) {
                // 三长一短：选最短的
                for (int j = 0; j < 4; j++) {
                    if (lens[j] == min) {
                        System.out.println(opts[j]);
                    }
                }
            } else if (uniqueMax && !uniqueMin) {
                // 三短一长：选最长的
                for (int j = 0; j < 4; j++) {
                    if (lens[j] == max) {
                        System.out.println(opts[j]);
                    }
                }
            } else {
                // 参差不齐：选 C
                System.out.println('C');
            }

        }

    }

    /*最厉害的学生*/
    private static void node69() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int number = Integer.parseInt(br.readLine()); // 读取学生数量
        int maxTotal = -1;
        String result = "";

        for (int i = 0; i < number; i++) {
            // 读取一行，包含当前学生的所有信息（格式：姓名 分数1 分数2 分数3）
            String[] info = br.readLine().split(" ");

            Students student = new Students();
            student.setName(info[0]); // 姓名
            student.setScore1(info[1]);
            student.setScore2(info[2]);
            student.setScore3(info[3]);

            // 计算当前学生总分，与最高分比较
            int currentTotal = student.total();
            if (currentTotal > maxTotal) {
                maxTotal = currentTotal;
                result = String.valueOf(student.getName() + " " + student.getScore1() + " " + student.getScore2() + " " + student.getScore3());
            }
        }

        System.out.println(result); // 输出最高分学生的姓名
    }

    private static void node70() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int step = Integer.parseInt(br.readLine());
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < step; i++) {
            String[] command = br.readLine().split(" ");


        }
    }

    private static void node76() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        LinkedList<Integer> list = new LinkedList<>();
        int total = Integer.parseInt(br.readLine());
        for (int i = 0; i < total; i++) {
            String[] command = br.readLine().split(" ");

            if (command.length == 1) {
                if (command[0].equals("2") && !list.isEmpty()) {
                    list.removeLast();
                }
                if (command[0].equals("5") && !list.isEmpty()) {
                    Collections.sort(list);
                }
                if (command[0].equals("6") && !list.isEmpty()) {
                    Collections.sort(list);
                    Collections.reverse(list);
                }
                if (command[0].equals("7")) {
                    System.out.println(list.size());
                }
                if (command[0].equals("8") && !list.isEmpty()) {
                    System.out.println(list.stream().map(String::valueOf).collect(Collectors.joining(" ")));
                }
            } else if (command.length == 2) {
                if (!command[1].isEmpty() && command[0].equals("1")) {
                    list.add(Integer.parseInt(command[1]));
                }
                if (!command[1].isEmpty() && command[0].equals("3")) {
                    int index = Integer.parseInt(command[1]);
                    System.out.println(list.get(index));
                }
            } else {
                if (!command[2].isEmpty() && !command[1].isEmpty() && command[0].equals("4")) {
                    int index = Integer.parseInt(command[1]);
                    list.add(index + 1, Integer.parseInt(command[2]));
                }
            }
        }
    }

    private static void node83() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int step = Integer.parseInt(br.readLine());
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < step; i++) {
            String[] command = br.readLine().split(" ");
            if (command.length == 1) {
                if (command[0].equals("query") && !stack.isEmpty()) {
                    System.out.println(stack.peek());
                }
                if (command[0].equals("query") && stack.isEmpty()) {
                    System.out.println("Empty");;
                }
                if (command[0].equals("pop")) {
                    stack.pop();
                }
                if (command[0].equals("size")) {
                    System.out.println(stack.size());
                }
            }else
                if (command[0].equals("push")) {
                    stack.push(Integer.parseInt(command[1]));
                }
        }
    }
}
